#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

using std::placeholders::_1;


namespace sub_topic
{
    class topic_sub : public rclcpp :: Node
    {
    private:
        rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub_;
        void topic_sub_cb(const std_msgs::msg::String & str) 
        {
            RCLCPP_INFO(this->get_logger(),str.data.c_str());
        }
    public:
        topic_sub(std::string name);
        ~topic_sub();
    };
    
    topic_sub::topic_sub(std::string name) : Node(name)
    {
        RCLCPP_INFO(this->get_logger(),"topic_sub_fun");
        sub_ = this->create_subscription<std_msgs::msg::String>("topic_pub_sub",10,std::bind(&topic_sub::topic_sub_cb,this,_1));
    }
    
    topic_sub::~topic_sub()
    {
    }
    
} // namespace sub_topic


int main(int argc, char  **argv)
{
    rclcpp::init(argc,argv);
    auto node = std::make_shared<sub_topic::topic_sub>("topic_sub");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
